//
//  StorageBrandsCell.m
//  danpin
//
//  Created by chuangjia on 15/12/2015.
//  Copyright © 2015 chuangjia. All rights reserved.
//

#import "StorageBrandsCell.h"

@interface StorageBrandsCell ()
{
    
}
@property(nonatomic,strong)UIImageView *titleIcon;
@property(nonatomic,strong)UILabel *nameLabel;
@property(nonatomic,strong)UIView *lineview;

@end
@implementation StorageBrandsCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor=[UIColor clearColor];
        
        _titleIcon =[[UIImageView alloc] initWithFrame:CGRectZero];
        _titleIcon.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_titleIcon];
        //
        _nameLabel =[[UILabel alloc] initWithFrame:CGRectMake(0,0, DEVICE_WIDTH/2,20)];
        _nameLabel.backgroundColor = [UIColor clearColor];
        _nameLabel.textColor = CONTEXT_COLOR;
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.font = FONT(12);
        [self.contentView addSubview:_nameLabel];
        
        _lineview =[[UIView alloc] initWithFrame:CGRectZero];
        _lineview.backgroundColor=UIColorFromRGB(0xe5e5e5);
        [self.contentView addSubview:_lineview];
        
        
    }
    return self;
}
-(void)dealloc
{
    self.actionBlock =nil;
    self.data=nil;
    self.indexPath=nil;
    self.other=nil;
    self.key=nil;
    
    [self.nameLabel removeFromSuperview];
    self.nameLabel=nil;
    self.lineview=nil;
    
    //    DLog(@"%s", __PRETTY_FUNCTION__);
}
- (void)drawRect:(CGRect)rect {
    
    [super drawRect:rect];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.key =key;
    self.indexPath=indexPath;
    NSDictionary *dict =(NSDictionary*)model;
    
    self.data =model;
    
    float fLeft = PHOTO_FRAME_WIDTH;
    NSString *icon =[dict stringForKey:@"image" withDefaultValue:@""];
    if (icon.length>0) {
        self.titleIcon.frame =CGRectMake(PHOTO_FRAME_WIDTH,PHOTO_TIME_PADDING, PHOTO_FRAME_WIDTH*3, PHOTO_FRAME_WIDTH*3);
        [self.titleIcon sd_setImageWithURL:[NSURL URLWithString:icon]];
        fLeft  = PHOTO_FRAME_WIDTH*5;
    }
    
    NSString *title =[dict stringForKey:@"name" withDefaultValue:@""];
    if (title.length>0) {
        _nameLabel.text =title;
        _nameLabel.frame =CGRectMake(fLeft, PHOTO_FRAME_WIDTH,DEVICE_WIDTH, 20);
    }
   
    [self layoutSubviews];
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}
/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    return PHOTO_FRAME_WIDTH*4;
}

@end
